package com.lv.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.lv.entity.Role;
import com.lv.entity.UserRole;
import com.lv.mapper.UserRoleMapper;
import com.lv.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 凉薄
 * @since 2022-01-06
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public Role getUserRole(Long id) {
        Role role = userRoleMapper.selectJoinOne(Role.class, new MPJLambdaWrapper<UserRole>()
                .selectAll(Role.class)
                .leftJoin(Role.class, Role::getId, UserRole::getRoleId)
                .eq(UserRole::getUserId, id));
        return role;
    }
}
